//
//  HNSH_SignGoodsCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/4/22.
//

#import "HNSH_SignGoodsCell.h"

@interface HNSH_SignGoodsCell ()
/** 图片 */
@property (nonatomic, strong)UIImageView * imgView;
/** 名字 */
@property (nonatomic, strong)UILabel * nameLabel;
/** 送积分*/
@property (nonatomic, strong)UILabel * sendJfLabel;
/** 送积分背景 */
@property (nonatomic, strong)UIImageView * sendJfBgImgV;
/** 价格 */
@property (nonatomic, strong)UILabel * priceLabel;
@end

@implementation HNSH_SignGoodsCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor appWhiteLabelColor];
        self.contentView.backgroundColor = [UIColor appWhiteLabelColor];
        [self configUI];
    }
    return self;
}

- (void)setModel:(HNSH_GoodsListModel *)model {
    _model = model;
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:model.cover_url]];
    self.nameLabel.text = model.name;
    
    self.priceLabel.text = [NSString stringWithFormat:@"%.2f",[model.bean_price doubleValue]];
    
    self.sendJfLabel.hidden = self.sendJfBgImgV.hidden = [model.price doubleValue] <= 0;
    self.sendJfLabel.text = [NSString stringWithFormat:@"价值：%.2f元",[model.price doubleValue]];
}

- (void)configUI {
    [self.contentView addSubview:self.imgView];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.sendJfBgImgV];
    [self.contentView addSubview:self.sendJfLabel];
    [self.contentView addSubview:self.priceLabel];
    
    CGFloat w = (kScreenWidth - 50) / 2.0;
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(0);
        make.height.mas_equalTo(w);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(self.imgView.mas_bottom).offset(16);
        make.height.mas_equalTo(20);
    }];

    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(6);
        make.left.mas_equalTo(self.nameLabel);
        make.height.mas_equalTo(21);
    }];
    
    [self.sendJfLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(14);
        make.top.mas_equalTo(self.priceLabel.mas_bottom).offset(3);
        make.height.mas_equalTo(13);
    }];
    [self.sendJfBgImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.sendJfLabel.mas_top);
        make.left.mas_equalTo(self.sendJfLabel.mas_left).offset(-4);
        make.right.mas_equalTo(self.sendJfLabel.mas_right).offset(4);
        make.height.mas_equalTo(13);
    }];
    
    self.nameLabel.text = @"苹果认证自带线充电宝";
    self.priceLabel.text = @"75.00汇豆";
    self.sendJfLabel.text = @"价值：135.00元";
}


//MARK: Getter Methods
- (UIImageView *)imgView{
    if (!_imgView) {
        _imgView = [UIImageView new];
        _imgView.backgroundColor = [UIColor grayColor];
    }
    return _imgView;
}

- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [UILabel new];
        _nameLabel.textColor = [UIColor appBlackLabelColor];
        _nameLabel.font = [UIFont boldSystemFontOfSize:14];
        _nameLabel.text = @"";
    }
    return _nameLabel;
}

- (UILabel *)sendJfLabel{
    if (!_sendJfLabel) {
        _sendJfLabel = [UILabel new];
        _sendJfLabel.text = @"";
        _sendJfLabel.textColor = [UIColor appWhiteLabelColor];
        _sendJfLabel.font = [UIFont systemFontOfSize:9];
    }
    return _sendJfLabel;
}

- (UIImageView *)sendJfBgImgV {
    if (!_sendJfBgImgV) {
        _sendJfBgImgV = [UIImageView new];
        _sendJfBgImgV.image = [UIImage imageNamed:@"home_goods_cell_jf_bg"];
    }
    return _sendJfBgImgV;
}

- (UILabel *)priceLabel {
    if (!_priceLabel) {
        _priceLabel = [UILabel new];
        _priceLabel.text = @"";
        _priceLabel.textColor = [UIColor colorWithHexString:@"#F73525"];
        _priceLabel.font = [UIFont boldSystemFontOfSize:15];
    }
    return _priceLabel;
}


@end
